package com.linfeng.component.common.exception;

import java.util.Arrays;

public enum CustomExceptionCode {

    /********************** 系统相关开始 code 为 1000~1099  **********************/
    SYSTEM_EXCEPTION(1000, "系统异常"),

    SYSTEM_NOT_FOUND(1001, "未找到"),

    DATA_NOT_FOUND(2001, "数据查询不到"),

    LOGIN_FAIL(10000, "登陆失败"),

    TOKEN_VERIFY(10001, "token验证失败"),

    TOKEN_LOSS(10002, "token丢失"),

    USERNAME_OR_PASSWORD_ERROR(10003, "用户名或密码错误"),

    UNAUTHORIZED(10004, "认证方式异常"),

    OK(200, "success"),
    ;


    private Integer code;
    private String description;

    private CustomExceptionCode(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static String getDescription(Integer code) {

        return Arrays.stream(CustomExceptionCode.values())
                .filter(obj -> obj.code.equals(code))
                .findFirst()
                .orElseThrow(() -> new CustomException(SYSTEM_NOT_FOUND))
                .getDescription();
    }
}
